<?php
namespace Home\Controller;
use Think\Controller;
// var_dump($_POST);
class FormsController extends CommonController {
    public function index(){
    	$uid = $_SESSION['id'];
    	$forms = M('mvp_forms');
    	$forms1 = M('mvp_formfoods');
    	$foods = M('mvp_foods');
    	$where['mvp_forms.uid'] = array('eq',$uid);
    	$where['mvp_forms.status'] = array('eq',0); 
    	$finfos = $forms->where($where)->join('mvp_formfoods on mvp_forms.formnumber = mvp_formfoods.formfoodsnumber')->select();
        $formsinfo = $forms->where($where)->select();
        // var_dump($formsinfo);die;
    	foreach ($finfos as $key => $value) {
    		
    		$foodsinfo = $foods->where('id = '.$value['fid'])->select();
    		// var_dump($foodsinfo);
    		$finfos[$key]['pic'] = $foodsinfo[0]['fpic'];
    		$finfos[$key]['foodsname'] = $foodsinfo[0]['name'];
    		$finfos[$key]['foodsprice'] = $foodsinfo[0]['price'];
    		// var_dump($foodsinfo);
    	}
    	// echo $forms->_sql();
    	// var_dump($finfos);
        $this->assign('formsinfo',$formsinfo);
    	$this->assign('finfos',$finfos);
    	$this->display();
    }
   public function Psindex(){
    	$uid = $_SESSION['id'];
    	$forms = M('mvp_forms');
    	$forms1 = M('mvp_formfoods');
    	$foods = M('mvp_foods');
    	$where['mvp_forms.uid'] = array('eq',$uid);
    	$where['mvp_forms.status'] = array('eq',1); 
    	$finfos = $forms->where($where)->join('mvp_formfoods on mvp_forms.formnumber = mvp_formfoods.formfoodsnumber')->select();
        $formsinfo = $forms->where($where)->select();
    	foreach ($finfos as $key => $value) {
    		
    		$foodsinfo = $foods->where('id = '.$value['fid'])->select();
    		// var_dump($foodsinfo);
    		$finfos[$key]['pic'] = $foodsinfo[0]['fpic'];
    		$finfos[$key]['foodsname'] = $foodsinfo[0]['name'];
    		$finfos[$key]['foodsprice'] = $foodsinfo[0]['price'];
    		// var_dump($foodsinfo);
    	}
    	// echo $forms->_sql();
    	// var_dump($finfos);
        $this->assign('formsinfo',$formsinfo);
    	$this->assign('finfos',$finfos);
    	$this->display();
    }
    public function Dpjindex(){
    	$uid = $_SESSION['id'];
    	$forms = M('mvp_forms');
    	$forms1 = M('mvp_formfoods');
    	$foods = M('mvp_foods');
    	$where['mvp_forms.uid'] = array('eq',$uid);
    	$where['mvp_forms.status'] = array('eq',3); 
    	$finfos = $forms->where($where)->join('mvp_formfoods on mvp_forms.formnumber = mvp_formfoods.formfoodsnumber')->select();
        $formsinfo = $forms->where($where)->select();
    	foreach ($finfos as $key => $value) {
    		
    		$foodsinfo = $foods->where('id = '.$value['fid'])->select();
    		// var_dump($foodsinfo);
    		$finfos[$key]['pic'] = $foodsinfo[0]['fpic'];
    		$finfos[$key]['foodsname'] = $foodsinfo[0]['name'];
    		$finfos[$key]['foodsprice'] = $foodsinfo[0]['price'];
    		// var_dump($foodsinfo);
    	}
    	// echo $forms->_sql();
    	// var_dump($finfos);
    	$this->assign('finfos',$finfos);
        $this->assign('formsinfo',$formsinfo);
    	$this->display();
    }
    public function Ypjindex(){
    	$uid = $_SESSION['id'];
    	$forms = M('mvp_forms');
    	$forms1 = M('mvp_formfoods');
    	$foods = M('mvp_foods');
    	$where['mvp_forms.uid'] = array('eq',$uid);
    	$where['mvp_forms.status'] = array('eq',4); 
    	$finfos = $forms->where($where)->join('mvp_formfoods on mvp_forms.formnumber = mvp_formfoods.formfoodsnumber')->select();
        $formsinfo = $forms->where($where)->select();
    	foreach ($finfos as $key => $value) {
    		
    		$foodsinfo = $foods->where('id = '.$value['fid'])->select();
    		// var_dump($foodsinfo);
    		$finfos[$key]['pic'] = $foodsinfo[0]['fpic'];
    		$finfos[$key]['foodsname'] = $foodsinfo[0]['name'];
    		$finfos[$key]['foodsprice'] = $foodsinfo[0]['price'];
    		// var_dump($foodsinfo);
    	}
    	// echo $forms->_sql();
    	//var_dump($finfos);
    	$this->assign('finfos',$finfos);
        $this->assign('formsinfo',$formsinfo);
    	$this->display();
    }
    public function Qxdd(){
        // var_dump($_GET);
        $forms = M('mvp_forms');
        $forms->create();
        $data['status'] = 5;
        $formsinfo = $forms->where('formnumber = '.$_GET['number'])->save($data);
        // echo $forms->_sql();
        // var_dump($formsinfo);die;
        if($formsinfo == 1){
            $this->success('取消成功',U('Home/Forms/index'),3);
        }else{
            $this->error('取消失败',U('Home/Forms/index'),3);

        }

    }
        public function Qxddindex(){
        $uid = $_SESSION['id'];
        $forms = M('mvp_forms');
        $forms1 = M('mvp_formfoods');
        $foods = M('mvp_foods');
        $where['mvp_forms.uid'] = array('eq',$uid);
        $where['mvp_forms.status'] = array('eq',5); 
        $finfos = $forms->where($where)->join('mvp_formfoods on mvp_forms.formnumber = mvp_formfoods.formfoodsnumber')->select();
        $formsinfo = $forms->where($where)->select();
        foreach ($finfos as $key => $value) {
            
            $foodsinfo = $foods->where('id = '.$value['fid'])->select();
            // var_dump($foodsinfo);
            $finfos[$key]['pic'] = $foodsinfo[0]['fpic'];
            $finfos[$key]['foodsname'] = $foodsinfo[0]['name'];
            $finfos[$key]['foodsprice'] = $foodsinfo[0]['price'];
            // var_dump($foodsinfo);
        }
        // echo $forms->_sql();
        //var_dump($finfos);
        $this->assign('finfos',$finfos);
        $this->assign('formsinfo',$formsinfo);
        $this->display();
    }
    public function Pjindex(){
         // var_dump($_GET);
        $uid = $_SESSION['id'];
        $forms = M('mvp_forms');
        $forms1 = M('mvp_formfoods');
        $foods = M('mvp_foods');
        $where['mvp_forms.uid'] = array('eq',$uid);
        $where['mvp_forms.status'] = array('eq',3);
        $where['mvp_forms.formnumber'] = array('eq',$_GET['formnumber']);
        $finfos = $forms->where($where)->join('mvp_formfoods on mvp_forms.formnumber = mvp_formfoods.formfoodsnumber')->select();

        foreach ($finfos as $key => $value) {
            
            $foodsinfo = $foods->where('id = '.$value['fid'])->select();
            // var_dump($foodsinfo);
            $finfos[$key]['pic'] = $foodsinfo[0]['fpic'];
            $finfos[$key]['foodsname'] = $foodsinfo[0]['name'];
            $finfos[$key]['foodsprice'] = $foodsinfo[0]['price'];
            // var_dump($foodsinfo);
        }
         // echo $forms->_sql();
        // var_dump($finfos);
        $this->assign('finfos',$finfos);
        $this->display();
    }
    public function UpdatePj(){
       
        // var_dump($_POST);
        $uid = $_SESSION['id'];
        $comtime = time();
        $formnumber = $_POST['formnumber0'];
        // var_dump($uid);
        for ($i=0; $i < count($_POST)/4; $i++) { 
           $arr[$i]['comment']=$_POST['content'.$i];
           $arr[$i]['fid']=$_POST['fid'.$i];
           $arr[$i]['score']=$_POST['score'.$i];
           $arr[$i]['uid'] = $uid;
           $arr[$i]['comtime']=$comtime;
        }
        // var_dump($arr);
        foreach ($arr as $key => $value) {
            // var_dump($value);
             //创建模型 
            $comment=M('mvp_comment');
            $comment->create();
            $commentinfo=$comment->add($value);
        }
        
        // var_dump($commentinfo);
        if($commentinfo){
            $forms=M('mvp_forms');
           
            $data['status'] =4;
            // var_dump($where);die;
            $formsinfo = $forms->where('formnumber = '.$formnumber)->save($data);
            // echo $forms->_sql();
            // var_dump($formsinfo);
            if($formsinfo){
                $this->success('评价成功',U('Home/Forms/index'),3);
            }else{
                $this->error('评价失败',U('Home/Forms/Ypjindex'),3);

            }

        }
    }
}

